package com.sangeng.controller;
import com.sangeng.mapper.Exception.SystemException;
import com.sangeng.entity.ResponseResult;
import com.sangeng.entity.User;
import com.sangeng.enums.AppHttpCodeEnum;
import com.sangeng.service.LoginUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController

public class LoginController {
    @Autowired
    LoginUserService userService;

    @PostMapping("/login")
    public ResponseResult login(@RequestBody User user){
      if(!StringUtils.hasText(user.getUserName()))
      {
          throw new SystemException(AppHttpCodeEnum.REQUIRE_USERNAME);

      }
      return   userService.login(user);

    }

    @RequestMapping("/logout")
    public ResponseResult logOut(){

       return userService.logOut();
    }

    @PostMapping("/user/register")
    public ResponseResult registerUser(@RequestBody User user){

        return userService.registerUser(user);


    }

}
